/**
 * 标签编辑
 * @param exports
 * @returns
 */
layui.define(['common','api','form','layer','laytpl'],function(exports){
	var laytpl = layui.laytpl;
	var $ = layui.jquery;
	var form = layui.form();
	var layer = layui.layer;

	var api = layui.api;
	var common = layui.common;

	//监听提交
  	form.on('submit(formDemo)', function(data){
		api.editTag(data.field,function(res){
			if(res.status == 200){
				layer.alert(res.msg, {
		          icon: 1,
		          end:function(){
		          	location.href = '/blog/back/tag';
		          }
		    });
			} else {
				layer.msg(res.msg || res.code, {
				shift: 6
			});
			}
		});
		return false;
  	});

  	var action = {
  		getTag:function(){
  			var id = common.getUrlParam("id");
  			var params = {
  				id:id
  			}
  			api.getTag(params,function(res){
  				console.log(res);
  				if(res.status == 200){
    				laytpl($("#template").html()).render(res.data,function(html){
    					$("#content-cnt").html(html);
    					form.render();
    				});
    			} else {
    				layer.msg(res.msg || res.code, {
    					shift: 6
    				});
	    		}
  			});
  		}
  	}

  	action.getTag();	
	exports('tag-edit',{});
});